package edu.gxnu.cetcdemo.controller;

import edu.gxnu.cetcdemo.pojo.Prop;
import edu.gxnu.cetcdemo.service.PropService;
import edu.gxnu.cetcdemo.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/prop")
public class PropController {
    @Autowired
    private PropService propService;
    @PostMapping("/search/{pageNumber}")
    @ApiOperation(value = "按页查询失物接口")
    public Result search(@RequestBody Map<String,Object> map, @PathVariable int pageNumber){
        Result result = propService.search(map, pageNumber);
        return result;
    }

    @PostMapping("/search/")
    @ApiOperation(value = "查询失物接口")
    public Result search_(@RequestBody Map<String,Object> map){
        Result result = propService.search(map, 1);
        return result;
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加失物接口")
    public Result add(@RequestBody Prop prop){
        if (propService.save(prop)){
            return new Result().build(200,"success",null);
        }else{
            return new Result().build(400,"fail",null);
        }
    }

    @PutMapping("/update")
    public Result update(@RequestBody Prop prop){
        return propService.updateProp(prop);
    }
}
